#!/bin/sh - 


sqlcmd()
{
    file=$1
    db=$2

    sqlcmd="mysql -h localhost -uroot -p123456 --default-character-set=utf8 "

    if [ -n "$db" ];then
        sqlcmd+=" -D $db"
    fi

    if [ -e "$file" ];then
        echo "run $db->$file... "
        $sqlcmd -f < $file || true
    else
        echo "run $@"
        echo $@ | $sqlcmd || true
    fi
}

sql_init()
{
    sqldir="/"

    echo "init database  script..."

    sqlcmd 'create database blog;'
    sqlcmd $sqldir/blog.sql blog 

    echo "over database script..."

    # 没有权限
    # cp -fv $sqldir/init.cnf /etc/mysql/conf.d/init.cnf
    # whoami
}


sql_init
